package com.mi.fastbird.mybstis.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 * 字段填充处理器
 *
 * @author 王永吉
 * @date 2019/10/31
 */
@Slf4j
public class ColumnFillHandler implements MetaObjectHandler {

    //数据创建时间
    private final String createTime = "createTime";
    //数据修改时间
    private final String updateTime = "updateTime";

    @Override
    public void insertFill(MetaObject metaObject) {
        try {
            setInsertFieldValByName(createTime, LocalDateTime.now(), metaObject);
        } catch (Exception e) {
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        try {
            setUpdateFieldValByName(updateTime, LocalDateTime.now(), metaObject);
        } catch (Exception e) {
        }
    }

}
